<template>
	<view>
		<view v-show="certImageUrl">
			<image :src="certImageUrl" style="width:100%;height:1000upx;"></image>
			
			<!--
			<view style="margin-top:20upx;padding:20upx;">
				<button class="main_btn" @click="downloadCert">下载证书</button>
			</view>
			-->
		</view>
		<view v-show="!certImageUrl" style="text-align: center;margin-top:300upx;">
			
			<view>
				<view>
					<image src="../../static/icon/nodata.png" style="width: 148upx;height: 100upx;"></image>
				</view>
				<text style="color:#868686;">未查询到证书</text>
			</view>
		</view>
		<view  v-show="certImageUrl" >
			<text style="font-size:24upx;color:red;padding-left:30upx;">注：长按图片可保存证书图片至手机</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				certImageUrl: '',
			}
		},
		onLoad() {
			this.getMyCert()
		},
		methods: {
			// 查询考生证书
			getMyCert(){
				let url = '/my/cert'
				uni.showLoading({
					title: "请求中..."
				})
				this.$H.post(url, {}, {token: true}).then(res=>{
					if(!res || res.code != 200){
						return uni.showToast({
							title: '获取数据失败'
						})
					}
					uni.hideLoading()
					let result = res.result
					if(result.downloadLink){
						this.certImageUrl = res.result.downloadLink
					}else{
						uni.showToast({
							title: '未查询到证书',
							icon: 'none'
						})
					}
				}).catch( err =>{
					if(err.msg){
						uni.showToast({
							title: err.msg,
							icon: 'none'
						})
					}
					uni.hideLoading()
				})
			},
			
			
			// 保存证书
			// 下载图片并保存到相册
			downloadCert() {
				
				let imgLink = document.createElement('a')
				imgLink.download = 'abc'
				imgLink.href = this.certImageUrl
				document.body.appendChild(imgLink)
				imgLink.click()
				imgLink.remove()
			}


		}
	}
</script>

<style>

</style>